package com.dcits.idea.dialog;

import com.dcits.idea.data.DataCenter;
import com.dcits.idea.data.NodeData;
import com.dcits.idea.util.CoverNodeData;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationDisplayType;
import com.intellij.notification.NotificationGroup;
import com.intellij.notification.Notifications;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.MessageDialogBuilder;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.ui.Messages;
import com.intellij.ui.EditorTextField;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;

/**
 * @Author tangmqb DCITS
 * @DATE 2021/11/3 11:18
 * @Version 1.0.0
 */
public class AddNoteDialog extends DialogWrapper {

    public  EditorTextField tfTitle;
    public EditorTextField tfMark;
    public AddNoteDialog() {
        super(true);
        setTitle("添加笔记");
        init();
    }


    @Nullable
    @Override
    protected JComponent createCenterPanel() {
        JPanel tfPanel = new JPanel(new BorderLayout());
        tfTitle = new EditorTextField();
        tfMark = new EditorTextField();
        tfTitle.setText("笔记标题");
        tfMark.setText("笔记内容");
        tfMark.setPreferredSize(new Dimension(200,100));
        tfPanel.add(tfTitle,BorderLayout.NORTH);
        tfPanel.add(tfMark,BorderLayout.CENTER);
        return tfPanel;
    }


    @Override
    protected JComponent createSouthPanel() {
        JPanel tfPanel = new JPanel();
        JButton jButton = new JButton("OK");
        jButton.addActionListener(e -> {
            System.out.println(tfTitle.getText()+":"+tfMark.getText());
            NodeData one = new NodeData(tfTitle.getText(), tfMark.getText(), DataCenter.SELECTED_TEXT, DataCenter.CURRENT_FILE_NAME, DataCenter.CURRENT_FILE_TYPE);
            DataCenter.NOTE_LIST.add(one);
            DataCenter.TABLE_MODEL.addRow(CoverNodeData.coverToArr(one));
//            MessageDialogBuilder.yesNo("操作结果", "添加笔记成功").show();
            Messages.showMessageDialog("添加笔记成功","操作结果",null);
            System.out.println("添加笔记成功");
            //添加成功关闭弹框
            dispose();
        });
        tfPanel.add(jButton);
        return tfPanel;
    }
}
